package 动态规划;

import java.util.Scanner;

/**
 * @description:
 * @author: ywk
 * @date: 2020-09-20
 */
public class 最少水携带 {
    /**
     小明横穿沙漠，需要携带至少x毫升的水。

     有两种规格的矿泉水可供选购：小瓶矿泉水每瓶500ml，价格a元。大瓶矿泉水每瓶1500ml，价格b元。

     小明打算买一些矿泉水用于横穿沙漠，为了保证至少买到x毫升的水，小明至少需要花费多少钱？
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int lines = sc.nextInt();
        int[][] arr = new int[lines][3];
        for (int i = 0; i < lines; i++) {
            for (int j = 0; j < 3; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        buyMax(arr);
    }

    public static void buyMax(int[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            int[] temp = arr[i];
            System.out.println(resolve(temp));
        }
    }

    private static int resolve(int[] temp) {
        int lite = temp[0];
        int smallPrice = temp[1];
        int bigPrice = temp[2];
        int smallSize = 500;
        int bigSize = 1500;

        if (lite % 500 != 0) {
            lite = (lite / 500 + 1) * 500;
        }
        //比较性价比
        boolean smallFirst = false;
        int money = 0;
        if (new Double(smallSize) / new Double(smallPrice) > new Double(bigSize) / new Double(bigPrice)) {
            smallFirst = true;
        }
        if (smallFirst) {
            int add = 1;
            if (lite % smallSize == 0) {
                add = 0;
            }
            money += (lite / smallSize + add) * smallPrice;

        } else {
            int rest = (lite % bigSize);
            money += (lite / bigSize) * bigPrice;
            int add = 1;
            if (rest % smallSize == 0) {
                add = 0;
            }
            money += ((rest / smallSize) + add) * smallPrice;
        }
        return money;
    }


}
